package com.service.impl;

import com.constant.AppConstant;
import com.entity.SysServer;
import com.repository.SysServerRepository;
import com.service.ServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Yadasu
 * @date 2021/1/28 16:38
 */
@Service
public class ServerServiceImpl implements ServerService {


    @Autowired
    private SysServerRepository serverRepository;
    @Override
    public List<SysServer> findAll() {
        return serverRepository.findAll();
    }



    /**
     * 新增服务器
     * @param sysServer 服务器相关信息
     * @return
     */
    @Override
    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public SysServer addProjectServer(SysServer sysServer) {
        if (sysServer.getServerPort()!=null){
            return serverRepository.save(sysServer);
        }else {
            sysServer.setServerPort(AppConstant.DEFAULT_SERVER_PORT);
            return serverRepository.save(sysServer);

        }

    }
}
